package com.zc.angelica.entity;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.List;

/**
 * (Account)表实体类
 *
 * @author makejava
 * @since 2022-04-04 12:00:10
 */
@Data
public class Account extends Model<Account> implements UserDetails {
    /**
     * 唯一标识
     */
    private Long id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 是否锁定（ 1 未锁定 2 锁定 ）
     */
    private Integer lockedlag;
    /**
     * 最后登录时间
     */
    private Date lastLoginTime;
    /**
     * 是否启用 （ 1 未禁用 2 已禁用 ）
     */
    private Integer isEnabled;
    /**
     * 账户过期 （ 1 未过期 2 已过期 3 永不过期）
     */
    private Integer isExpired;
    /**
     * 过期时间
     */
    private Date expiredTime;
    /**
     * 错误登录错误次数
     * */
    private Integer errors;
    /**
     * 解锁时间
     * */
    private Date unlockTime;

    /**
     * 平台信息
     * */
    @TableField(exist = false)
    private List<PlatformInfo> platforms;

    /**
     * 持久化登录
     * */
    @TableField(exist = false)
    private  List<AccountClient> lasting ;


    @TableField(exist = false)
    private Collection<? extends GrantedAuthority> authorities;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.isExpired != 2;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.isExpired != 2;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled != 2;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }


    /**
     * 获取主键值
     *
     * @return 主键值
     */
    @Override
    public Serializable pkVal() {
        return this.id;
    }
}

